
#include <bits/stdc++.h>

const int N = 1e6 + 10;

using namespace std;

int a[N],b[N],n; 

int find()
{
	int st1 = 1,ed1 = n;
	int st2 = 1,ed2 = n;
	int mid1 = st1 + ed1 >> 1;
	int mid2 = st2 + ed2 >> 1;
	while(st1 < ed1 and st2 < ed2)
	{
		mid1 = st1 + ed1 >> 1;
		mid2 = st2 + ed2 >> 1;
		if(a[mid1] == b[mid2]) return a[mid1];
		else if(a[mid1] < b[mid2])
		{
			if((st1 + ed1)%2==0) st1 = mid1;
			else st1 = mid1 + 1;
			ed2 = mid2;
		}
		else
		{
			if((st2 + ed2)%2==0)st2 = mid2;
			else st2 = mid2 + 1;
			ed1 = mid1;
		}
			
	}
	return a[st1] < b[st2] ? a[st1] : b[st2];
}

void slove()
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cin >> b[i]; 
	cout<<find();
}
int main() {
	int T = 1;
	//cin >> T;
	while(T--)slove();



	return 0;
}

